home *** CD-ROM | disk | FTP | other *** search
- Path: shell.portal.com!not-for-mail
- From: clare@shell.portal.com (Clare Chu)
- Newsgroups: comp.lang.c++
- Subject: Virtual Constructors (how to implement)?
- Date: 15 Feb 1996 17:12:14 -0800
- Organization: Portal Communications Company -- 408/973-9111 (voice) 408/973-8091 (data)
- Message-ID: <4g0lle$nmq@jobe.shell.portal.com>
- NNTP-Posting-Host: jobe.shell.portal.com
-
-
- I have an abstract base class Packet. Inherited from Packet
- are specific packets like LoginPacket, AuditPacket, etc.
-
- What I need is to read a socket (stream), and then construct
- the packet of the right kind, depending on what it is.
-
- I read a reference to this technique in Scott Meyer's More Effective C++
- but I haven't received my copy yet. (It is back-ordered at Computer
- Literacy).
-
- I need someone to basically outline what I need to do to set
- up such a function that reads from a stream, produces the appropriate
- object and returns a pointer to Packet pointing to the object
- which is of the appropriate derived class.
-
- At present, I'm trying to implement it as an array of pointers
- to functions. Those functions will be called based on the
- Packet type, and create the appropriate object. Of course I
- haven't even thought about going out of scope, destructors,
- or such. My coworker says to just use a big switch statement
- and construct objects based on the type.
-
- Any ideas?
-
- Thanks in advance,
- Clare
- clare@shell.portal.com
-
-
-
-